package com.trip.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import com.trip.dao.tables.pojos.PlanDiscussionDomain;
import com.trip.dao.tables.pojos.PlanItemDetailLikeDomain;
import com.trip.dao.tables.pojos.TripPlanDomain;
import com.trip.dao.tables.pojos.TripPlanItemDetailDomain;
import com.trip.dao.tables.pojos.UserDomain;
import com.trip.dao.tables.records.*;
import com.trip.exception.ServiceException;
import com.trip.util.OneSignalUtil;
import com.trip.vo.*;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.trip.dao.Tables.*;

/**
 * Created by hc24 on 2017/10/7.
 */
@Service
@Transactional
public class TripPlanService {

    @Autowired
    private DSLContext dslContext;

    @Autowired
    private PlaceAndExperienceService placeAndExperienceService;

    @Autowired
    private UserService userService;

    public TripPlanDomain save(TripPlanRequest planRequest){
       TripPlanRecord planRecord= dslContext.newRecord(TRIP_PLAN);
       planRecord.from(planRequest);
       planRecord.setCreatedAt(LocalDateTime.now());
       planRecord.setPartnerCount(planRequest.getUserIds()==null?0:planRequest.getUserIds().size());
       planRecord.insert();

       List<TripPlanItemRecord> itemList=new ArrayList<>();
       for(int i=0;i<planRecord.getTravelDays();i++){
           TripPlanItemRecord item=new TripPlanItemRecord();
           item.setDayDate(planRecord.getTravelDate().plusDays(i));
           item.setDayIndex(i);
           item.setPlanId(planRecord.getId());

           itemList.add(item);
       }
       dslContext.batchInsert(itemList).execute();


        planRequest.getUserIds().add(planRequest.getCreatedBy());
       addPartner(planRecord.getId(),planRequest.getUserIds());

       return planRecord.into(TripPlanDomain.class);
    }

    public TripPlanDomain update(Integer planId,TripPlanRequest planRequest){
        TripPlanRecord record=dslContext.selectFrom(TRIP_PLAN).where(TRIP_PLAN.ID.eq(planId)).fetchOne();

        int oldDays= record.getTravelDays();
        int newDays=planRequest.getTravelDays();

        record.setGroupName(planRequest.getGroupName());
        record.setTravelDate(planRequest.getTravelDate());
        record.setTravelDays(planRequest.getTravelDays());
        record.setCoverId(planRequest.getCoverId());
        record.setPartnerCount(planRequest.getUserIds()==null?0:planRequest.getUserIds().size());

        record.update();

        dslContext.deleteFrom(PLAN_PARTNERS).where(PLAN_PARTNERS.PLAN_ID.eq(planId)).execute();
        if(planRequest.getUserIds()!=null&&planRequest.getUserIds().size()>0){
            List<PlanPartnersRecord> partnersList= planRequest.getUserIds().stream().map(e->{
                PlanPartnersRecord partnersRecord=new PlanPartnersRecord();
                partnersRecord.setPlanId(planId);
                partnersRecord.setJoinTime(LocalDateTime.now());
                partnersRecord.setUserId(e);

                return partnersRecord;
            }).collect(Collectors.toList());

            dslContext.batchInsert(partnersList).execute();
        }


        List<TripPlanItemRecord> oldItemList=dslContext.selectFrom(TRIP_PLAN_ITEM)
                .where(TRIP_PLAN_ITEM.PLAN_ID.eq(planId))
                .orderBy(TRIP_PLAN_ITEM.DAY_INDEX.asc())
                .fetch();

        if(newDays>=oldDays){
            List<TripPlanItemRecord> addItemList=new ArrayList<>();
            for(int i=0;i<record.getTravelDays();i++){
                if(i<oldItemList.size()){
                    oldItemList.get(i).setDayDate(record.getTravelDate().plusDays(i));
                }else{
                    TripPlanItemRecord item=new TripPlanItemRecord();
                    item.setDayDate(record.getTravelDate().plusDays(i));
                    item.setDayIndex(i);
                    item.setPlanId(record.getId());

                    addItemList.add(item);
                }
            }

            dslContext.batchUpdate(oldItemList).execute();

            if(addItemList.size()>0){
                dslContext.batchInsert(addItemList).execute();
            }
        }else{
            //update item
            List<TripPlanItemRecord> updateItemList=new ArrayList<>();
            for(int i=0;i<record.getTravelDays();i++){
                oldItemList.get(i).setDayDate(record.getTravelDate().plusDays(i));
                updateItemList.add(oldItemList.get(i));
            }

            //====set unplaned===
            TripPlanItemRecord unplanedItemRecord=null;
            for(TripPlanItemRecord itemRecord:oldItemList){
                if(itemRecord.getDayDate()==null){
                    unplanedItemRecord=itemRecord;
                    break;
                }
            }

            if(unplanedItemRecord==null) {
                unplanedItemRecord=oldItemList.get(record.getTravelDays());
            }

            unplanedItemRecord.setDayDate(null);
            unplanedItemRecord.setDayIndex(record.getTravelDays());
            updateItemList.add(unplanedItemRecord);
            //===end set unplaned ===

            dslContext.batchUpdate(updateItemList).execute();


            List<Integer> deleteItemIdList=new ArrayList<>();
            for(int i=record.getTravelDays();i<oldDays;i++){
                if(!oldItemList.get(i).getId().equals(unplanedItemRecord.getId()))
                    deleteItemIdList.add(oldItemList.get(i).getId());
            }

            if(deleteItemIdList.size()>0) {
                //move the needless's detail to unplaned item
                dslContext.update(TRIP_PLAN_ITEM_DETAIL)
                        .set(TRIP_PLAN_ITEM_DETAIL.PLAN_ITEM_ID, unplanedItemRecord.getId())
                        .where(TRIP_PLAN_ITEM_DETAIL.PLAN_ITEM_ID.in(deleteItemIdList))
                        .execute();

                //delete the needless item
                dslContext.deleteFrom(TRIP_PLAN_ITEM).where(TRIP_PLAN_ITEM.ID.in(deleteItemIdList)).execute();
            }
        }

        return record.into(TripPlanDomain.class);
    }

    public void delete(Integer planId,Integer userId){
        int c=dslContext.deleteFrom(TRIP_PLAN).where(TRIP_PLAN.ID.eq(planId),TRIP_PLAN.CREATED_BY.eq(userId)).execute();
        if(c==0)
            return;
        dslContext.deleteFrom(TRIP_PLAN_ITEM).where(TRIP_PLAN_ITEM.PLAN_ID.eq(planId)).execute();
        dslContext.deleteFrom(TRIP_PLAN_ITEM_DETAIL).where(TRIP_PLAN_ITEM_DETAIL.PLAN_ID.eq(planId)).execute();
        dslContext.deleteFrom(PLAN_DISCUSSION).where(PLAN_DISCUSSION.PLAN_ID.eq(planId)).execute();
        dslContext.deleteFrom(PLAN_PARTNERS).where(PLAN_PARTNERS.PLAN_ID.eq(planId)).execute();
    }

    @Transactional(readOnly = true)
    public List<TripPlanDomain> queryPastList(Integer userId){
        return dslContext.select(TRIP_PLAN.fields()).from(TRIP_PLAN)
                .leftJoin(PLAN_PARTNERS).on(TRIP_PLAN.ID.eq(PLAN_PARTNERS.PLAN_ID))
                .where(TRIP_PLAN.TRAVEL_DATE.lt(LocalDate.now()))
                .and(PLAN_PARTNERS.USER_ID.eq(userId))
                .orderBy(TRIP_PLAN.TRAVEL_DATE.desc())
                .fetchInto(TripPlanDomain.class);
    }

    @Transactional(readOnly = true)
    public List<TripPlanDomain> queryFutureList(Integer userId){
        return dslContext.select(TRIP_PLAN.fields()).from(TRIP_PLAN)
                .leftJoin(PLAN_PARTNERS).on(TRIP_PLAN.ID.eq(PLAN_PARTNERS.PLAN_ID))
                .where(TRIP_PLAN.TRAVEL_DATE.ge(LocalDate.now()))
                .and(PLAN_PARTNERS.USER_ID.eq(userId))
                .orderBy(TRIP_PLAN.TRAVEL_DATE.desc())
                .fetchInto(TripPlanDomain.class);
    }

    @Transactional(readOnly = true)
    public List<TripPlanItemVo> queryItemList(Integer planId){
        List<TripPlanItemVo> list= dslContext.select(TRIP_PLAN_ITEM.fields()).select(TRIP_PLAN_ITEM_DETAIL.ID.count().as("detailCount")).from(TRIP_PLAN_ITEM)
                .leftJoin(TRIP_PLAN_ITEM_DETAIL).on(TRIP_PLAN_ITEM_DETAIL.PLAN_ITEM_ID.eq(TRIP_PLAN_ITEM.ID))
                .where(TRIP_PLAN_ITEM.PLAN_ID.eq(planId))
                .groupBy(TRIP_PLAN_ITEM.ID)
                .fetchInto(TripPlanItemVo.class);

//        list.forEach(e->{
//            dslContext.selectCount().from(TRIP_PLAN_ITEM_DETAIL.)
//        });

        return list;
    }

    public List<TripPlanItemDetailVo> queryItemDetailList(Integer itemId,Integer selfId){
        List<TripPlanItemDetailVo> list= dslContext.selectFrom(TRIP_PLAN_ITEM_DETAIL)
                .where(TRIP_PLAN_ITEM_DETAIL.PLAN_ITEM_ID.eq(itemId))
                .orderBy(TRIP_PLAN_ITEM_DETAIL.SEQ.asc())
                .fetchInto(TripPlanItemDetailVo.class);
        for(TripPlanItemDetailVo detail:list){
            detail.setLikeList(queryLikeList(detail.getId()));
            detail.setLiked(liked(detail.getId(),selfId));
        }

        return list;
    }

    private Boolean liked(Integer detailId,Integer userId){

           Record1<Boolean> record= dslContext.select(PLAN_ITEM_DETAIL_LIKE.USER_ID.nvl2(true,false).as("liked")).from(PLAN_ITEM_DETAIL_LIKE)
            .where(PLAN_ITEM_DETAIL_LIKE.USER_ID.eq(userId),PLAN_ITEM_DETAIL_LIKE.PLAN_ITEM_DETAIL_ID.eq(detailId))
            .fetchOne();

           if(record==null)
               return false;

           return record.value1();
    }

    public void sortItemDetail(List<Integer> detailSet){
        int seq=0;
        for(Integer detailId:detailSet){
            dslContext.update(TRIP_PLAN_ITEM_DETAIL)
                    .set(TRIP_PLAN_ITEM_DETAIL.SEQ,seq)
                    .where(TRIP_PLAN_ITEM_DETAIL.ID.eq(detailId))
                    .execute();
            seq++;
        }
    }

    public void moveItemDetail(Integer detailId,Integer toItemId,List<Integer> detailSet){
        moveItemDetail(detailId,toItemId);
        sortItemDetail(detailSet);
    }

    public void moveItemDetail(Integer detailId,Integer toItemId){
        dslContext.update(TRIP_PLAN_ITEM_DETAIL)
                .set(TRIP_PLAN_ITEM_DETAIL.PLAN_ITEM_ID,toItemId)
                .set(TRIP_PLAN_ITEM_DETAIL.SEQ,100)
                .where(TRIP_PLAN_ITEM_DETAIL.ID.eq(detailId))
                .execute();
    }

    @Transactional(readOnly = true)
    public List<DiscussionVo> queryDiscussionList(Integer planId){
        return dslContext.select(PLAN_DISCUSSION.fields()).select(USER.AVATAR,USER.NICK_NAME,USER.ID.as("userId"))
                .select(PIC.HEIGHT.as("picHeight"),PIC.WIDTH.as("picWidth"))
                .from(PLAN_DISCUSSION)
                .leftJoin(USER).on(PLAN_DISCUSSION.USER_ID.eq(USER.ID))
                .leftJoin(PIC).on(PLAN_DISCUSSION.PIC_ID.eq(PIC.ID))
                .where(PLAN_DISCUSSION.PLAN_ID.eq(planId))
                .orderBy(PLAN_DISCUSSION.CREATED_AT.asc())
                .fetchInto(DiscussionVo.class);
                //.fetchStream().map(e->e.into(DiscussionVo.class)).collect(Collectors.toList());
    }

    public PlanDiscussionDomain addDiscussion(PlanDiscussionDomain discussion){
        PlanDiscussionRecord planDiscussionRecord= dslContext.newRecord(PLAN_DISCUSSION);
        planDiscussionRecord.from(discussion);
        planDiscussionRecord.insert();

        PlanDiscussionReadRecord record= dslContext.newRecord(PLAN_DISCUSSION_READ);
        record.setDiscussionId(planDiscussionRecord.getId());
        record.setPlanId(discussion.getPlanId());
        record.setUserId(planDiscussionRecord.getUserId());
        record.setReadFlag(true);

        record.insert();

        TripPlanRecord plan=dslContext.selectFrom(TRIP_PLAN).where(TRIP_PLAN.ID.eq(discussion.getPlanId())).fetchOne();
        //UserDomain user = userService.query(discussion.getUserId());
        List<UserSimpleVo> partnerList = queryPartner(discussion.getPlanId());
        List<String> userIds = partnerList.stream().map(e -> e.getUserId() + "").filter(e -> !e.equals(discussion.getUserId() + "")).collect(Collectors.toList());

        Executors.newSingleThreadExecutor().submit(()->OneSignalUtil.pushMessage(userIds,plan.getGroupName()));

        return planDiscussionRecord.into(PlanDiscussionDomain.class);
    }

    public List<UserSimpleVo> queryPartner(Integer planId){
        return dslContext.select(USER.ID.as("userId"),USER.INTRO,USER.AVATAR,USER.NICK_NAME,USER.COVER).from(PLAN_PARTNERS)
                .leftJoin(USER).on(USER.ID.eq(PLAN_PARTNERS.USER_ID))
                .where(PLAN_PARTNERS.PLAN_ID.eq(planId))
                .fetchInto(UserSimpleVo.class);
    }

    public void addPartner(Integer planId,Set<Integer> userIdSet){
        Set<Integer> existingSet= dslContext.select(PLAN_PARTNERS.USER_ID).from(PLAN_PARTNERS)
                .where(PLAN_PARTNERS.PLAN_ID.eq(planId))
                .fetchSet(PLAN_PARTNERS.USER_ID);


        if(existingSet.size()>0) {
            userIdSet.addAll(existingSet);
            dslContext.deleteFrom(PLAN_PARTNERS).where(PLAN_PARTNERS.PLAN_ID.eq(planId)).execute();
        }

        List<PlanPartnersRecord> partnersList=new ArrayList<>();
        for(Integer userId:userIdSet){
            PlanPartnersRecord partnersRecord=new PlanPartnersRecord();
            partnersRecord.setPlanId(planId);
            partnersRecord.setJoinTime(LocalDateTime.now());
            partnersRecord.setUserId(userId);

            partnersList.add(partnersRecord);
        }

        dslContext.batchInsert(partnersList).execute();

        updatePartnerCount(planId);
    }

    public void deletePartner(Integer planId,Set<Integer> userIdSet){
        dslContext.deleteFrom(PLAN_PARTNERS).where(PLAN_PARTNERS.PLAN_ID.eq(planId))
                .and(PLAN_PARTNERS.USER_ID.in(userIdSet))
                .execute();

        updatePartnerCount(planId);
    }

    private void updatePartnerCount(Integer planId){
        Integer count=dslContext.selectCount().from(PLAN_PARTNERS)
                .where(PLAN_PARTNERS.PLAN_ID.eq(planId))
                .fetchOne().value1();

        dslContext.update(TRIP_PLAN).set(TRIP_PLAN.PARTNER_COUNT,count).where(TRIP_PLAN.ID.eq(planId)).execute();
    }

    public List<TripPlanItemDetailDomain> addItemDetail(Integer itemId,String[] paeIds){

        Integer count=dslContext.selectCount().from(TRIP_PLAN_ITEM_DETAIL)
                .where(TRIP_PLAN_ITEM_DETAIL.PAE_ID.in(paeIds),TRIP_PLAN_ITEM_DETAIL.PLAN_ITEM_ID.eq(itemId))
                .fetchOne().value1();
        if(count>0)
            throw new ServiceException("You have added your selected place or experience");

        List<PlaceAndExpRecord> placeAndExpRecordList= placeAndExperienceService.query(paeIds);
        TripPlanItemRecord itemRecord=dslContext.selectFrom(TRIP_PLAN_ITEM).where(TRIP_PLAN_ITEM.ID.eq(itemId)).fetchOne();

        if(placeAndExpRecordList.size()==0)
            throw new ServiceException("Place or Experience is not existent");

        if(itemRecord==null)
            throw new ServiceException("Trip item is not existent");

        List<TripPlanItemDetailRecord> detailRecordList=new ArrayList<>();
        for(PlaceAndExpRecord placeAndExpRecord:placeAndExpRecordList) {
            TripPlanItemDetailRecord itemDetailRecord = new TripPlanItemDetailRecord();
            itemDetailRecord.setPlanItemId(itemId);
            itemDetailRecord.setPlanId(itemRecord.getPlanId());
            itemDetailRecord.setDayIndex(itemRecord.getDayIndex());
            itemDetailRecord.setPaeId(placeAndExpRecord.getId());
            itemDetailRecord.setPaeTitle(placeAndExpRecord.getTitle());
            itemDetailRecord.setPaeCover(placeAndExpRecord.getCover());
            itemDetailRecord.setPaePlayTime(placeAndExpRecord.getPlayDuration());
            itemDetailRecord.setLikeCount(0);

            detailRecordList.add(itemDetailRecord);
        }

        dslContext.batchInsert(detailRecordList).execute();

        return detailRecordList.stream().map(e->e.into(TripPlanItemDetailDomain.class)).collect(Collectors.toList());
    }

    public void deleteItemDetail(Integer itemDetailId){
        dslContext.deleteFrom(TRIP_PLAN_ITEM_DETAIL).where(TRIP_PLAN_ITEM_DETAIL.ID.eq(itemDetailId)).execute();
        dslContext.deleteFrom(PLAN_ITEM_DETAIL_LIKE).where(PLAN_ITEM_DETAIL_LIKE.PLAN_ITEM_DETAIL_ID.eq(itemDetailId)).execute();
    }

    public PlanItemDetailLikeDomain like(Integer detailId, Integer userId){
        PlanItemDetailLikeRecord record=queryLikeRecord(detailId,userId);
        int n=0;
        if(record==null){
            record=dslContext.newRecord(PLAN_ITEM_DETAIL_LIKE);

            UserDomain userDomain= userService.query(userId);
            if(userDomain==null)
                throw new ServiceException("User is not exists");

            record.setLikeTime(LocalDateTime.now());
            record.setUserId(userId);
            record.setUserAvatar(userDomain.getAvatar());
            record.setPlanItemDetailId(detailId);

            n=record.insert();
        }

        dslContext.update(TRIP_PLAN_ITEM_DETAIL).set(TRIP_PLAN_ITEM_DETAIL.LIKE_COUNT,TRIP_PLAN_ITEM_DETAIL.LIKE_COUNT.plus(n)).where(TRIP_PLAN_ITEM_DETAIL.ID.eq(detailId)).execute();

        return record.into(PlanItemDetailLikeDomain.class);
    }

    public void cancelLike(Integer detailId,Integer userId){
        int n=dslContext.deleteFrom(PLAN_ITEM_DETAIL_LIKE)
                .where(PLAN_ITEM_DETAIL_LIKE.PLAN_ITEM_DETAIL_ID.eq(detailId))
                .and(PLAN_ITEM_DETAIL_LIKE.USER_ID.eq(userId))
                .execute();

        dslContext.update(TRIP_PLAN_ITEM_DETAIL).set(TRIP_PLAN_ITEM_DETAIL.LIKE_COUNT,TRIP_PLAN_ITEM_DETAIL.LIKE_COUNT.minus(n)).where(TRIP_PLAN_ITEM_DETAIL.ID.eq(detailId)).execute();
    }

    @Transactional(readOnly = true)
    public List<LikeUserVo> queryLikeList(Integer detailId){
        return dslContext.select(PLAN_ITEM_DETAIL_LIKE.fields()).select(USER.NICK_NAME,USER.INTRO).from(PLAN_ITEM_DETAIL_LIKE)
                .leftJoin(USER).on(USER.ID.eq(PLAN_ITEM_DETAIL_LIKE.USER_ID))
                .where(PLAN_ITEM_DETAIL_LIKE.PLAN_ITEM_DETAIL_ID.eq(detailId))
                .orderBy(PLAN_ITEM_DETAIL_LIKE.LIKE_TIME.desc())
                .fetchInto(LikeUserVo.class);
    }

    @Transactional(readOnly = true)
    public PlanItemDetailLikeDomain queryLike(Integer detailId, Integer userId){
        PlanItemDetailLikeRecord record=queryLikeRecord(detailId,userId);
        return record==null?null:record.into(PlanItemDetailLikeDomain.class);
    }

    public void deletePartner(Integer selfId,Integer partnerId){
        List<TripPlanRecord> list= dslContext.selectFrom(TRIP_PLAN).where(TRIP_PLAN.CREATED_BY.eq(selfId)).fetch();
        list.forEach(e->{
            int num= dslContext.deleteFrom(PLAN_PARTNERS)
                    .where(PLAN_PARTNERS.PLAN_ID.eq(e.getId()))
                    .and(PLAN_PARTNERS.USER_ID.eq(partnerId))
                    .execute();
            if(num>0){
                e.setPartnerCount(e.getPartnerCount()-num);
                e.update();
            }
        });
    }

    private PlanItemDetailLikeRecord queryLikeRecord(Integer detailId, Integer userId){
        return dslContext.selectFrom(PLAN_ITEM_DETAIL_LIKE)
                .where(PLAN_ITEM_DETAIL_LIKE.PLAN_ITEM_DETAIL_ID.eq(detailId))
                .and(PLAN_ITEM_DETAIL_LIKE.USER_ID.eq(userId))
                .fetchOne();
    }

    public void setDiscussionReaded(Integer planId,List<Integer> discussionIds,Integer userId){
        List<Integer> existingDiscussionIds = dslContext.selectFrom(PLAN_DISCUSSION_READ).where(PLAN_DISCUSSION_READ.USER_ID.eq(userId))
                .and(PLAN_DISCUSSION_READ.DISCUSSION_ID.in(discussionIds))
                .fetch(PLAN_DISCUSSION_READ.DISCUSSION_ID);
        discussionIds.removeAll(existingDiscussionIds);
        List<PlanDiscussionReadRecord> list=new ArrayList<>();
        for(Integer discussionId:discussionIds){
            PlanDiscussionReadRecord record= dslContext.newRecord(PLAN_DISCUSSION_READ);
            record.setDiscussionId(discussionId);
            record.setPlanId(planId);
            record.setUserId(userId);
            record.setReadFlag(true);

            list.add(record);
        }
        dslContext.batchInsert(list).execute();
    }

    public List<PlanDiscussionCountVo> unreadDiscussionCount(Integer userId){
        List<PlanDiscussionCountVo> discussionCountList = dslContext.select(PLAN_DISCUSSION.PLAN_ID.count().as("count")).select(PLAN_PARTNERS.PLAN_ID).from(PLAN_PARTNERS)
                .leftJoin(PLAN_DISCUSSION).on(PLAN_PARTNERS.PLAN_ID.eq(PLAN_DISCUSSION.PLAN_ID))
                .where(PLAN_PARTNERS.USER_ID.eq(userId))
                .groupBy(PLAN_PARTNERS.PLAN_ID)
                .fetchInto(PlanDiscussionCountVo.class);
        Map<Integer,Integer> readedCountMap= dslContext.selectCount().select(PLAN_DISCUSSION_READ.PLAN_ID).from(PLAN_DISCUSSION_READ)
                .where(PLAN_DISCUSSION_READ.USER_ID.eq(userId))
                .groupBy(PLAN_DISCUSSION_READ.PLAN_ID)
                .fetchInto(PlanDiscussionCountVo.class)
                .stream().collect(Collectors.toMap(PlanDiscussionCountVo::getPlanId,PlanDiscussionCountVo::getCount));


        Set<PlanDiscussionCountVo> set=new HashSet<>();

        for(PlanDiscussionCountVo vo:discussionCountList){
            Integer readed= readedCountMap.get(vo.getPlanId());
            if(readed!=null){
                vo.setCount(vo.getCount()-readed);
                vo.setCount(vo.getCount()<0?0:vo.getCount());
            }

        }

        //return discussionCount-readedCount;
        return discussionCountList;
    }

}
